import { Form, message } from 'antd';
import { WeaTop, WeaInput, WeaTools, WeaLocaleProvider, WeaErrorPage } from 'ecCom';
// import CarConstant from '../../../util/CarConstant';
import { inject, observer } from 'mobx-react';
// import CarUseSingtonDialog from './CarUseSingtonDialog';
import '../../../style/index';

const getLabel = WeaLocaleProvider.getLabel;
const FormItem = Form.Item;
@inject('routing')
@observer
class CarViewSington extends React.Component {
  constructor(props) {
    super(props);
    const { id } = this.props.location.query;
    this.state = {
      visible: true,
      carid: id,
    };
  }

  getFieldValue = (fieldname, cardata) => {
    let val = '';
    if (cardata && cardata[fieldname]) {
      val = cardata[fieldname];
    }
    return val;
  }


  render() {
    document.title = getLabel(20316, '车辆信息');
    const { carid } = this.state;
    const formItemLayout = {
      labelCol: { span: 7 },
      wrapperCol: { span: 13 },
    };
    let cardata = {};
    if (carid > 0) {
      jQuery.ajax({
        type: 'GET',
        url: '/api/car/base/getCarInfo',
        data: { id: carid, timestamp: new Date() },
        dataType: 'json',
        async: false,
        success(result) {
          if (result && result.status === '1') {
            cardata = result;
          } else {
            message.error(getLabel(385841, '获取车辆失败'));
          }
        },
      });
    }
    return (
      <div className="wea-car-mine">
        <WeaTop
          ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@y3i9hj`}
          title={getLabel(20316, '车辆信息')}
          icon={<i className="icon-coms-car" />}
          iconBgcolor="#1a57a0"
        />
        <div className="carview-dialog-form">
          <div id="carViewDiv" style={{ paddingTop: 20, paddingLeft: 30 }}>
            <Form ecId={`${this && this.props && this.props.ecId || ''}_Form@6lk45r`}>
              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@2a5sk0`}
                {...formItemLayout}
                id="carNo"
                name="carNo"
                label={`${getLabel(20319, '车牌号')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@ff8qx9`} viewAttr={1} value={this.getFieldValue('carNo', cardata)} />
              </FormItem>

              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@ex2xo9`}
                {...formItemLayout}
                id="subCompanyId"
                name="subCompanyId"
                label={`${getLabel(17868, '所属机构')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@jy2xy9`} viewAttr={1} value={this.getFieldValue('subCompanyIdName', cardata)} />
              </FormItem>


              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@utj3il`}
                {...formItemLayout}
                id="carType"
                name="carType"
                label={`${getLabel(17630, '车辆类型')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@cb88al`} viewAttr={1} value={this.getFieldValue('carTypeName', cardata)} />
              </FormItem>

              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@ghpjl7`}
                {...formItemLayout}
                id="usefee"
                name="usefee"
                label={`${getLabel(1491, '费用')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@b0abpc`} viewAttr={1} value={this.getFieldValue('usefee', cardata)} />
              </FormItem>

              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@9le9ii`}
                {...formItemLayout}
                id="factoryNo"
                name="factoryNo"
                label={`${getLabel(20318, '厂牌型号')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@35sjpk`} viewAttr={1} value={this.getFieldValue('factoryNo', cardata)} />
              </FormItem>

              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@szeudr`}
                {...formItemLayout}
                id="price"
                name="price"
                label={`${getLabel(20320, '购买价格')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@h6aaxh`} viewAttr={1} value={this.getFieldValue('price', cardata)} />
              </FormItem>

              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@y9pca6`}
                {...formItemLayout}
                id="buyDate"
                name="buyDate"
                label={`${getLabel(16914, '购置日期')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@zu4yjg`} viewAttr={1} value={this.getFieldValue('buyDate', cardata)} />
              </FormItem>

              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@ga0fpl`}
                {...formItemLayout}
                id="engineNo"
                name="engineNo"
                label={`${getLabel(20322, '发动机号码')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@o8w4vx`} viewAttr={1} value={this.getFieldValue('engineNo', cardata)} />
              </FormItem>

              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@pwepfd`}
                {...formItemLayout}
                id="driver"
                name="driver"
                label={`${getLabel(17649, '司机')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@hk3ko3`} viewAttr={1} value={this.getFieldValue('driverName', cardata)} />
              </FormItem>
              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@vfucki`}
                {...formItemLayout}
                id="remark"
                name="remark"
                label={`${getLabel(454, '备注')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@82tuzp`} viewAttr={1} value={this.getFieldValue('remark', cardata)} />
              </FormItem>
              <FormItem
                ecId={`${this && this.props && this.props.ecId || ''}_FormItem@0v9gq2`}
                {...formItemLayout}
                id="deposit"
                name="deposit"
                label={`${getLabel(383297, '是否封存')}：`}
              >
                <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@2jb17k`} viewAttr={1} value={this.getFieldValue('deposit', cardata) == '1' ? getLabel(163, '是') : getLabel(161, '否')} />
              </FormItem>
            </Form>
          </div>
        </div>
      </div>
    );
  }
}

export default WeaTools.tryCatch(React,
  props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@efyjwu`} msg={props.error ? props.error : '对不起，该页面异常，请联系管理员！'} />,
  { error: '' },
)(CarViewSington);
